home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Icon 8.1 / mep1 / External Functions / Samples / Code Resource Sources / OpenResFile.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-28  |  1.4 KB  |  62 lines  |  [TEXT/KAHL]

  1. /*
  2.  * ProIcon: Code resource to open a resource file.
  3.  *
  4.  * This code resource will appear under the resource type 'CODE', ID 1000,
  5.  * name "OpenResFile".  Invoke with:
  6.  *
  7.  *      resFile := callout("CODE","OpenResFile", s)
  8.  *
  9.  *      where s is the pathname of a resource file.
  10.  *
  11.  *      resFile is a simple integer.  The function fails if the file could
  12.  *      not be opened, or returns error 103 if s is not a string. 
  13.  */
  14.  
  15. #include "ProIcon.h"
  16. pointer memcopy(char *to, char *from, word n);
  17.  
  18. pascal dptr main(dargv, argc, ip, callback)
  19. dptr dargv;
  20. short int argc;
  21. short int *ip;
  22. pointer (*callback)();
  23. {
  24.    char sbuf[MaxCvtLen+1];
  25.    int resFile;
  26.  
  27.    if (argc != 1)                    /* fail if wrong number of arguments */
  28.       RunErr(Err103, NULL);
  29.  
  30.    switch (cvstr(&Arg1, &sbuf[1])) {
  31.       case Cvt:
  32.          break;
  33.       case NoCvt:
  34.          memcopy(&sbuf[1], StrLoc(Arg1),
  35.           StrLen(Arg1) > MaxCvtLen ? MaxCvtLen : StrLen(Arg1));
  36.          break;
  37.       default:
  38.          RunErr(Err103, &Arg1);        /* string expected as third argument */
  39.          }
  40.    sbuf[0] = StrLen(Arg1);                /* create Pascal-style string */
  41.  
  42.    if ((resFile = OpenResFile((StringPtr)sbuf)) == -1)
  43.       Fail;
  44.    MakeInt(resFile, &Arg0);
  45.       
  46.    Return;
  47. }
  48.  
  49.  
  50. pointer memcopy(to, from, n)
  51.    register char *to, *from;
  52.    register word n;
  53.    {
  54.    register char *p = to;
  55.  
  56.    while (--n >= 0)
  57.       *to++ = *from++;
  58.  
  59.    return (pointer)p;
  60.    }
  61.  
  62.